package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.vo.HourlyOrderDistributionVO;
import com.ruoyi.system.domain.vo.TodayStatisticsVO;
import com.ruoyi.system.domain.vo.RevenueTrendVO;
import com.ruoyi.system.domain.vo.MonthlyRevenueTrendVO;
import com.ruoyi.system.domain.vo.HourlyRevenueDistributionVO;
import com.ruoyi.system.mapper.TbOrderStatisticsMapper;
import com.ruoyi.system.service.ITbOrderStatisticsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

/**
 * 订单统计服务实现类
 */
@Service
public class TbOrderStatisticsServiceImpl implements ITbOrderStatisticsService {

    private static final Logger log = LoggerFactory.getLogger(TbOrderStatisticsServiceImpl.class);

    @Autowired
    private TbOrderStatisticsMapper orderStatisticsMapper;

    @Override
    public TodayStatisticsVO getTodayStatistics(String conpanyName) {
        TodayStatisticsVO result = orderStatisticsMapper.selectTodayStatistics(conpanyName);
        log.info("今日统计数据: {}", result);
        return result;
    }

    @Override
    public List<RevenueTrendVO> getRevenueTrend(Integer type,String conpanyName) {
        if (type == null || (type != 7 && type != 30)) {
            type = 7; // 默认查询近7天
        }
        
        List<RevenueTrendVO> result = orderStatisticsMapper.selectRevenueTrend(type,conpanyName);
        log.info("营收趋势数据: {}", result);
        return result;
    }

    @Override
    public List<MonthlyRevenueTrendVO> getMonthlyRevenueTrend(Integer type,String companyName) {
        if (type == null || (type != 3 && type != 12)) {
            type = 3; // 默认查询近3个月
        }
        
        List<MonthlyRevenueTrendVO> result = orderStatisticsMapper.selectMonthlyRevenueTrend(type,companyName);
        log.info("月营收趋势数据: {}", result);
        return result;
    }

    @Override
    public List<HourlyOrderDistributionVO> getHourlyOrderDistribution(String companyName) {
        return this.orderStatisticsMapper.selectHourlyOrderDistribution( companyName);
    }

    @Override
    public List<HourlyRevenueDistributionVO> getHourlyRevenueDistribution(String companyName) {
        return this.orderStatisticsMapper.selectHourlyRevenueDistribution(companyName);
    }
} 